using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace _395_2d
{
    public class HUD : Microsoft.Xna.Framework.DrawableGameComponent, ISubscriber
    {
        private SpriteBatch spriteBatch;
        private SpriteFont font;

        public int Score
        {
            get;
            private set;
        }

        private int Health = 100;

        public HUD(Game game)
            : base(game)
        {
            Score = 0;
        }

        protected override void LoadContent()
        {
            font = Game.Content.Load<SpriteFont>("HUDFont");
            spriteBatch = new SpriteBatch(this.Game.GraphicsDevice);

            base.LoadContent();
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
            spriteBatch.Begin();
            spriteBatch.DrawString(font, "Health: " + Health.ToString(), new Vector2(10, 10), Color.Red);
            spriteBatch.DrawString(font, "Score: " + Score.ToString(), new Vector2(10, 35), Color.Red);
            spriteBatch.End();
        }

        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here
            base.Update(gameTime);
        }

        public void Deliver(Message m)
        {
            if (m is ScoreChangeMessage)
            {
                ScoreChangeMessage scm = (ScoreChangeMessage)m;
                Score += scm.ScoreChange;
            }

            if (m is PlayerHealthMessage)
            {
                PlayerHealthMessage ph = (PlayerHealthMessage)m;
                Health = ph.Health;
            }
        }
    }
}
